home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
common
/
hydrasocket.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
2KB
|
51 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
import socket
from util import lock, do
from common.timeoutsocket import iptuples, TimeoutSocket
class HydraSocket(object):
def tryconnect(self, ips, on_connect, on_fail, timeout = 2, cls = TimeoutSocket):
self._ips = iptuples(ips)
self.on_connect = on_connect
self.on_fail = on_fail
self.timetowait = timeout
self.numfails = 0
self.success = False
self.socks = [ cls(False) for __ in self._ips ]
self.connected_sock = None
[ sock.tryconnect(ip, self.on_success, self.singlefail, timeout = self.timetowait) for sock, ip in zip(self.socks, self._ips) ]
def on_success(self, sock):
if self.success:
sock.do_disconnect()
else:
sock.cancel_timeout()
(do,)((lambda .0: for sock_ in .0:
if sock_ is not sock:
sock_.do_disconnect()continue)(self.socks))
self.success = True
self.connected_sock = sock
self.on_connect(sock)
on_success = lock(on_success)
def singlefail(self):
self.numfails += 1
if self.numfails >= len(self._ips):
self.on_fail()
singlefail = lock(singlefail)
def send(self, *a, **k):
if self.connected_sock is None:
raise socket.error('HydraSocket is not connected')
self.connected_sock.send(*a, **k)